const util = require("../../utils/util");

// pages/mine/mine.js
const app = getApp()
Page({
  data: {
    userInfo: {},
    openid: ''
  },
  onLoad: function (options) {

  },
  onReady: function () {

  },
  onShow: function () {
    let ui = wx.getStorageSync('userInfo');
    if (ui) {
      return this.setData({ userInfo: ui, openid: ui.openid })
    }
  },
  getUserInfo() {
    wx.getUserProfile({
      desc: '用于完善会员资料',
      success: res => {
        this.setData({
          userInfo: res.userInfo
        })
        wx.cloud.callFunction({
          name: 'login',
          success: res => {
            this.setData({
              openid: res.result.openid
            })
            this.data.userInfo.openid = res.result.openid
            wx.setStorageSync('userInfo', this.data.userInfo)
          }, fail: err => {
            console.log(err);
          }
        })
      }
    })
  },
  goBaBa(){
    util.route('/pages/detail/detail',{})
  },
  gocs(){
    util.route('/pages/chaoxihome/chaoxihome',{})
  }
})